package org.yinxianren.www.study_02.study.httpTest;


import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.Map;
import java.util.TreeMap;

public class PayTest {


    @org.junit.Test
    public void addCus(){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201001");
            map.put("merOrderId","201908060012");
            map.put("merchantType","00");
            map.put("terminalMerId","M201001-002");
            map.put("terminalMerName","詹光活");
            map.put("terminalMerShortName","詹光活");
            map.put("identityType","1");
            map.put("identityNum","350425199006012636");
            map.put("phone","18649624575");
            map.put("province","350000");
            map.put("city","350200");
            map.put("address","厦门翔安");
            map.put("bankCode","ABC");
            map.put("bankCardType","1");
            map.put("cardHolderName","詹光活");
            map.put("bankCardNum","6217001930018496760");
            map.put("bankCardPhone","17605083552");
            map.put("payFee","5");
            map.put("backFee","3");
            map.put("category","贸易");
            map.put("validDate","202011");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));
            String tradeInfo = JsonUtils.objectToJson(map);
//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/addCusInfo", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}
    @org.junit.Test
    public void bankCardBind(){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201001");
            map.put("merOrderId","20190806006");
            map.put("bankaccProp","0");
            map.put("identityType","1");
            map.put("identityNum","350425199006012636");
            map.put("bankCardType","1");
            map.put("cardHolderName","詹光活");
            map.put("bankCardNum","6217001930018496795");
            map.put("bankCardPhone","17605083552");
            map.put("province","350000");
            map.put("city","350200");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));

            String tradeInfo = JsonUtils.objectToJson(map);
//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/bankCardBind", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}
    @org.junit.Test
    public void serviceFul(){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201001");
            map.put("merOrderId","20190806006");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));

            String tradeInfo = JsonUtils.objectToJson(map);
//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/serviceFulfillment", postJson);
            System.out.println(content);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}





    @org.junit.Test
    public void BondCard(){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201001");
            map.put("merOrderId","201908080001");
            map.put("userName","詹光活");
            map.put("identityType","1");
            map.put("bankCardType","1");
            map.put("identityNum","350425199006012636");
            map.put("bankCardNum","6217001930018496760");
            map.put("bankCardPhone","17605083552");
            map.put("bankCode","CCB");
            map.put("validDate","202011");
            map.put("securityCode","123");
            map.put("terminalMerId","M201001-001");
            map.put("terminalMerName","test");
            map.put("returnUrl","http://...");
            map.put("noticeUrl","http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));
            String tradeInfo = JsonUtils.objectToJson(map);
//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/bondCard", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}
    @org.junit.Test
    public void confirmBond(){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201001");
            map.put("merOrderId","201907300001");
            map.put("identityType","1");
            map.put("bankCardType","1");
            map.put("userName","詹光活");
            map.put("identityNum","350425199006012636");
            map.put("bankCardNum","6217001930018496795");
            map.put("bankCode","CCB");
            map.put("bankCardPhone","17605083552");
            map.put("validDate","202011");
            map.put("securityCode","123");
            map.put("payFee","5");
            map.put("backFee","3");
            map.put("backCardNum","6217001930018496795");
            map.put("backBankCode","5");
            map.put("backCardPhone","17605083552");
            map.put("smsCode","111111");
            map.put("terminalMerId","M201001-001");
            map.put("terminalMerName","test");
            map.put("returnUrl","http://...");
            map.put("noticeUrl","http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));
            String tradeInfo = JsonUtils.objectToJson(map);
//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/confirmBond", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}
    @Test
    public void BondCardSms(){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201001");
            map.put("merOrderId","20190719002");
            map.put("userName","詹光活");
            map.put("identityType","1");
            map.put("bankCardType","1");
            map.put("identityNum","35425199006012636");
            map.put("bankCardNum","6217001930018496795");
            map.put("bankCardPhone","17605083552");
            map.put("bankCode","ABC");
            map.put("validDate","202011");
            map.put("securityCode","123");
            map.put("terminalMerId","M201001-001");
            map.put("terminalMerName","test");
            map.put("returnUrl","http://...");
            map.put("noticeUrl","http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));
            String tradeInfo = JsonUtils.objectToJson(map);
//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/reGetBondCode", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}




    @Test
    public  void payApply() {
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("bizType", "5");
            map.put("charset", "utf-8");
            map.put("signType", "MD5");
            map.put("merId", "M201001");
            map.put("merOrderId", "20190802000003");
            map.put("currency", "CNY");
            map.put("amount", "100");
            map.put("identityType", "1");
            map.put("bankCardType", "1");
            map.put("identityNum", "350425199006012636");
            map.put("bankCardNum", "6217001930018496795");
            map.put("bankCode", "CCB");
            map.put("validDate", "202211");
            map.put("securityCode", "123");
            map.put("bankCardPhone", "17605083552");
            map.put("payFee", "10");
            map.put("terminalMerId", "M201001-001");
            map.put("terminalMerName", "test");
            map.put("returnUrl", "http://...");
            map.put("noticeUrl", "http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map, "1iiG15c2"));
            String tradeInfo = JsonUtils.objectToJson(map);
            tradeInfo = URLEncoder.encode(tradeInfo, "UTF-8");
            String postJson = new String(Base64.getEncoder().encode(tradeInfo.getBytes()), "UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/pay/payApply", postJson);
            System.out.println(content);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }


    @Test
    public  void confirmPay() {
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("bizType", "5");
            map.put("charset", "utf-8");
            map.put("signType", "MD5");
            map.put("merId", "M201001");
            map.put("merOrderId", "20190802000001");
            map.put("smsCode", "111111");
            map.put("terminalMerId", "M201001-001");
            map.put("terminalMerName", "test");
            map.put("payFee", "10");
            map.put("noticeUrl", "http://...");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map, "1iiG15c2"));
            String tradeInfo = JsonUtils.objectToJson(map);

//            System.out.println(tradeInfo);
            tradeInfo = URLEncoder.encode(tradeInfo, "UTF-8");
            String postJson = new String(Base64.getEncoder().encode(tradeInfo.getBytes()), "UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8030/kuaijie/pay/confirmPay", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }
    @org.junit.Test
    public void confirmPaySms(){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("bizType","5");
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201002");
            map.put("merOrderId","2019070315390001");
            map.put("terminalMerId","M201002-009");
            map.put("terminalMerName","test");
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"lXN7z498"));
            String tradeInfo = JsonUtils.objectToJson(map);

//            System.out.println(tradeInfo);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://192.168.1.67:8050/kuaijie/pay/confirmSMS", postJson);
            System.out.println(content);

//            System.out.println(postJson);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }}


    @Test
    public  void daifu() throws UnsupportedEncodingException {
        Map<String, Object> map = new TreeMap<>();
        map.put("bizType","5");
        map.put("charset","utf-8");
        map.put("signType","MD5");
        map.put("merId","M201001");
        map.put("merOrderId","201907240000011");
        map.put("originalMerOrderId","2019072301000000000000");
        map.put("currency","CNY");
        map.put("amount","10");
        map.put("identityType","1");
        map.put("bankCardType","1");
        map.put("identityNum","350425199006012636");
        map.put("bankCardNum","6217001930018496795");
        map.put("bankCardPhone","17605083552");
        map.put("bankCode","CCB");
        map.put("backFee","7");
        map.put("terminalMerId", "M201001-001");
        map.put("terminalMerName","test");
        map.put("returnUrl","http://...");
        map.put("noticeUrl","http://...");
        map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));
        String tradeInfo = JsonUtils.objectToJson(map);
        tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
        String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
        String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://127.0.0.1:8070/kuaijie/getTransOrder", postJson);
        System.out.println(content);
    }

    @Test
    public void testHaiYi(){
        try {
            Map<String, Object> map = new TreeMap<>();
            map.put("bizType","4");
            map.put("charset","utf-8");
            map.put("signType","MD5");
            map.put("merId","M201001");
            map.put("merOrderId","201907130015000030");
            map.put("amount","10");
            map.put("bankCode","ABC");
            map.put("inAcctNo","6228480078071578275");
            map.put("inAcctName","谭廷东");
            map.put("returnUrl","http://...");
            map.put("noticeUrl","http://192.168.1.67:8001/cross/haiyiPay/testNoticeUrl");
            map.put("remark","代付测试");                              //lXN7z498    357g4Y4v
            map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));
            String tradeInfo = JsonUtils.objectToJson(map);
            tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
            String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8070/inwardPay/payForAnother", postJson);
//            String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://192.168.1.67:8050/inwardPay/payForAnother", postJson);
//                String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://outpay.xmfusepay.com/haiYiPay/payForAnother", postJson);
            System.out.println(content);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }




    @Test
    public  void haiYiDaiFu_1(){
        for(int i=0;i<1;i++){
            int id=i;
            try {
                Map<String, Object> map = new TreeMap<>();
                map.put("bizType","4");
                map.put("charset","utf-8");
                map.put("signType","MD5");
                map.put("merId","M201001");
                map.put("merOrderId","201907130015000030"+id);
                map.put("amount","10");
                map.put("bankCode","ABC");
                map.put("inAcctNo","6228480078071578275");
                map.put("inAcctName","谭廷东");
                map.put("returnUrl","http://...");
                map.put("noticeUrl","http://192.168.1.67:8001/cross/haiyiPay/testNoticeUrl");
                map.put("remark","代付测试");                              //lXN7z498    357g4Y4v
                map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"1iiG15c2"));
                String tradeInfo = JsonUtils.objectToJson(map);
                tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
                String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
//                   String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8070/haiYiPay/payForAnother", postJson);
                String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://192.168.1.67:8050/inwardPay/payForAnother", postJson);
//                String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://outpay.xmfusepay.com/haiYiPay/payForAnother", postJson);
                System.out.println(content);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    }




    public static void haiYiDaiFu_2(){
        for(int i=0;i<180;i++){
            int id=i;
            new Thread(()->{
                try {
                    Map<String, Object> map = new TreeMap<>();
                    map.put("bizType","4");
                    map.put("charset","utf-8");
                    map.put("signType","MD5");
                    map.put("merId","M201002");
                    map.put("merOrderId","201907130230"+id);
                    map.put("amount","10");
                    map.put("bankCode","ABC");
                    map.put("inAcctNo","6228480078071578275");
                    map.put("inAcctName","谭廷东");
                    map.put("returnUrl","http://...");
                    map.put("noticeUrl","http://192.168.1.67:8001/cross/haiyiPay/testNoticeUrl");
                    map.put("remark","代付测试");                              //lXN7z498    357g4Y4v
                    map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"lXN7z498"));
                    String tradeInfo = JsonUtils.objectToJson(map);
                    tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
                    String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
//                    String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://localhost:8070/haiYiPay/payForAnother", postJson);
                    String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://192.168.1.67:8050/inward/inwardPay/payForAnother", postJson);
//                String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://outpay.xmfusepay.com/haiYiPay/payForAnother", postJson);
                    System.out.println(content);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }


    public static void haiYiDaiFu_3(){
        for(int i=0;i<5;i++){
            int id=i;
            new Thread(()->{
                try {
                    Map<String, Object> map = new TreeMap<>();
                    map.put("bizType","4");
                    map.put("charset","utf-8");
                    map.put("signType","MD5");
                    map.put("merId","M201003");
                    map.put("merOrderId","201907150002000030005"+id);
                    map.put("amount","10");
                    map.put("bankCode","ABC");
                    map.put("inAcctNo","6228480078071578275");
                    map.put("inAcctName","谭廷东");
                    map.put("returnUrl","http://...");
                    map.put("noticeUrl","http://192.168.1.67:8001/cross/inwardPay/testNoticeUrl");
                    map.put("remark","代付测试");                              //lXN7z498    357g4Y4v
                    map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map,"357g4Y4v"));
                    String tradeInfo = JsonUtils.objectToJson(map);
                    tradeInfo= URLEncoder.encode(tradeInfo,"UTF-8");
                    String postJson= new String( Base64.getEncoder().encode(tradeInfo.getBytes()),"UTF-8");
                    String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://192.168.1.67:8050/inward/inwardPay/payForAnother", postJson);
//                    String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://inward.cmtbuy.com/inward/inwardPay/payForAnother", postJson);
//                String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://outpay.xmfusepay.com/inward/payForAnother", postJson);
                    System.out.println(content);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }


    @org.junit.Test
    public  void haiYiDaiFu_5() {
        for (int i = 0; i < 13; i++) {
            try {
                Map<String, Object> map = new TreeMap<>();
                map.put("bizType", "4");
                map.put("charset", "utf-8");
                map.put("signType", "MD5");
                map.put("merId", "M201001");
                map.put("merOrderId", "20190717001290001015"+i);
                map.put("amount", "10");
                map.put("bankCode", "ABC");
                map.put("inAcctNo", "6228480078071578888");
                map.put("inAcctName", "黄三");
                map.put("returnUrl", "http://www.baidu.com");
                map.put("noticeUrl", "http://www.baidu.com");
                map.put("remark", "代付测试");
                map.put("signMsg", CheckMd5Utils.getMd5SignWithKey(map, "1iiG15c2"));
                String tradeInfo = JsonUtils.objectToJson(map);
                tradeInfo = URLEncoder.encode(tradeInfo, "UTF-8");
                String postJson = new String(Base64.getEncoder().encode(tradeInfo.getBytes()), "UTF-8");
                String content = HttpClientUtils.doPostJson(HttpClientUtils.getHttpsClient(), "http://127.0.0.1:8070/inwardPay/payForAnother", postJson);
                System.out.println(content);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    }
    @Test
    public void test_012(){
        String test="#";
        System.out.println(test.matches("^#.+"));

    }




}
